package sg.edu.nus.iss.vmcs.customer;
import java.awt.Composite;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;

import sg.edu.nus.iss.vmcs.maintenance.AwtMaintenancePanel;
import sg.edu.nus.iss.vmcs.interfaces.Command;
import sg.edu.nus.iss.vmcs.interfaces.VMCSCommandAWTAdapter;
import sg.edu.nus.iss.vmcs.system.CoinInputListener;
import sg.edu.nus.iss.vmcs.system.MainController;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CoinInputBox extends Panel{
	
	private JLabel coinsTitle;
	private JButton invalidBtn;
	private JButton oneDollarBtn;
	private JButton fiftyCentBtn;
	private JButton twentyCentBtn;
	private JButton tenCentBtn;
	private JButton fiveCentBtn;
	private MainController mainController;
	private CoinReceiver receiver;
	private VMCSCommandAWTAdapter vmcsAdapter;
	
	public CoinInputBox(MainController mainCon,AwtCustomerPanel container,CoinReceiver receiver) {
		super();
		this.receiver = receiver;
		this.mainController=mainCon;
		new CoinInputListener(receiver,mainController);
		vmcsAdapter = new VMCSCommandAWTAdapter(new CoinInputCommand(receiver));
		initGUI();
	}

	private void initGUI() {
		try {
			{
				GridBagLayout thisLayout = new GridBagLayout();
				thisLayout.rowWeights = new double[] {0.1, 0.1};
				thisLayout.rowHeights = new int[] {7, 7};
				thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1,0.1,0.1};
				thisLayout.columnWidths = new int[] {7, 7, 7, 7,7,7};
				this.setLayout(thisLayout);
				{
					coinsTitle = new JLabel();
					this.add(coinsTitle, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(10, 10, 10, 10), 0, 0));
					coinsTitle.setText("Enter Coins Here");
					coinsTitle.setFont(new java.awt.Font("Segoe UI",1,14));
				}
				{
					fiveCentBtn = new JButton();
					this.add(fiveCentBtn, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					fiveCentBtn.setText("5c");
					/**
					 * Weight of the coin hard coded. This will be an output from weighing machine
					 * in real vending machine
					 */
					fiveCentBtn.setActionCommand("7");
					fiveCentBtn.addActionListener(vmcsAdapter);
				}
				{
					tenCentBtn = new JButton();
					this.add(tenCentBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					tenCentBtn.setText("10c");
					/**
					 * Weight of the coin hard coded. This will be an output from a mini weighing machine
					 * in real vending machine
					 */
					tenCentBtn.setActionCommand("10");
					tenCentBtn.addActionListener(vmcsAdapter);
				}
				{
					twentyCentBtn = new JButton();
					this.add(twentyCentBtn, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					twentyCentBtn.setText("20c");
					/**
					 * Weight of the coin hard coded. This will be an output from a mini weighing machine
					 * in real vending machine
					 */
					twentyCentBtn.setActionCommand("18");
					twentyCentBtn.addActionListener(vmcsAdapter);
				}
				{
					fiftyCentBtn = new JButton();
					this.add(fiftyCentBtn, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					fiftyCentBtn.setText("50c");
					/**
					 * Weight of the coin hard coded. This will be an output from a mini weighing machine
					 * in real vending machine
					 */
					fiftyCentBtn.setActionCommand("35");
					fiftyCentBtn.addActionListener(vmcsAdapter);
				}
				{
					oneDollarBtn = new JButton();
					this.add(oneDollarBtn, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					oneDollarBtn.setText("$ 1");
					/**
					 * Weight of the coin hard coded. This will be an output from a mini weighing machine
					 * in real vending machine
					 */
					oneDollarBtn.setActionCommand("42");
					oneDollarBtn.addActionListener(vmcsAdapter);
				}
				{
					invalidBtn = new JButton();
					this.add(invalidBtn, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 30, 10, 10), 0, 0));
					invalidBtn.setText("Invalid");
					/**
					 * Weight of the coin hard coded. This will be an output from a mini weighing machine
					 * in real vending machine
					 */
					invalidBtn.setActionCommand("9999");
					invalidBtn.addActionListener(vmcsAdapter);
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public void display() {
		this.setVisible(true);
	}
	
	public void disable(){
		this.setEnabled(false);
	}

}
